/**
 * VUEshop
 * ============================================================================
 * * 版权所有 2015-2027 深圳搜豹网络科技有限公司，并保留所有权利。
 * 网站地址: http://www.vueshop.com.cn
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
 * 不允许对程序代码以任何形式任何目的的再发布。
 * ============================================================================
 * $Author: soubao-java 2020-07-22 $
 */<template>
  <div>
    <div class="item-title">
      <div class="subject">
        <h3>提现申请管理</h3>
        <h5>网站系统提现申请索引与管理</h5>
      </div>
    </div>
    <div
      class="explanation"
      style="color: rgb(85, 85, 85); background-color: rgb(243, 244, 244); width: 98%; height: 100%;"
    >
      <div class="bckopa-tips">
        <div class="title">
          <img src="@/static/images/handd.png" alt />
          <h4 title="提示相关设置操作时应注意的要点">操作提示</h4>
        </div>
        <ul>
          <li>支付宝，微信在线转账需要申请相关支付接口以及设置管理员支付密码</li>
          <li>拒绝提现的申请记录才能删除</li>
          <li>审核通过的提现申请会进入待付款列表</li>
        </ul>
      </div>
      <span title="收起提示" id="explanationZoom" style="display: block;"></span>
    </div>
    <div class="mDiv">
      <div class="ftitle">
        <h3>店铺列表</h3>
        <h5>(共 {{totalCount}} 条记录)</h5>
      </div>
      <div class="fbutton">
        <div class="add" @click="updateBatch(1)">
          <span>
            <i class="el-icon-check" /> 审核通过
          </span>
        </div>
      </div>
      <div class="fbutton">
        <div class="add" @click="updateBatch(-1)">
          <span>
            <i class="el-icon-minus" /> 审核失败
          </span>
        </div>
      </div>
      <div class="fbutton">
        <div class="add" @click="updateBatch(-2)">
          <span>
            <i class="el-icon-close" /> 无效作废
          </span>
        </div>
      </div>
      <a href @click.prevent="refresh()" class="refresh-date">
        <div title="刷新数据" class="pReload">
          <i class="fa fa-refresh"></i>
        </div>
      </a>
      <div class="searchbox">
        <el-date-picker
          size="small"
          v-model="dateRange"
          type="daterange"
          align="right"
          unlink-panels
          range-separator="至"
          start-placeholder="下单日期起始"
          end-placeholder="下单日期截止"
        ></el-date-picker>
        <el-select v-model="status" size="small" clearable placeholder="状态">
          <el-option
            v-for="item in statusArr"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          ></el-option>
        </el-select>
        <el-input
          class="searchinput"
          v-model="store_id"
          width="10"
          size="small"
          placeholder="店铺ID"
          clearable
        />
        <el-input
          class="searchinput"
          v-model="realname"
          width="10"
          size="small"
          placeholder="银行账户"
          clearable
        />
        <el-input
          class="searchinput"
          v-model="bank_card"
          width="10"
          size="small"
          placeholder="银行账号"
          clearable
        />
        <el-button
          class="searchbtn"
          size="small"
          icon="el-icon-search"
          @click="currentPage = 1;getPage()"
        >搜索</el-button>
      </div>
    </div>
    <div class="tablebox" v-if="tableData">
      <el-table :data="tableData" ref="multipleTable" style="width: 100%;">
        <el-table-column type="selection" width="55"></el-table-column>
        <el-table-column label="申请ID" prop="id" width="90"></el-table-column>
        <el-table-column label="店铺id" prop="store_id" width="90" show-overflow-tooltip></el-table-column>
        <el-table-column label="店铺名称" prop="store_name" width="180"></el-table-column>
        <el-table-column label="申请时间" prop="create_time_desc" width="120"></el-table-column>
        <el-table-column label="申请金额" prop="money" width="110"></el-table-column>
        <el-table-column label="银行名称" prop="bank_name" width="120"></el-table-column>
        <el-table-column label="银行账号" prop="bank_card" width="180"></el-table-column>
        <el-table-column label="银行账户" prop="realname" width="120"></el-table-column>
        <el-table-column label="状态" prop="status_desc" width="100"></el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button-group>
              <el-button size="small" @click="detail(scope.row.id)" icon="el-icon-edit-outline">编辑</el-button>
              <el-button
                size="small"
                v-if="scope.row.status == -2 || scope.row.status == -1"
                @click="delFn(scope.row.id)"
                icon="el-icon-delete"
              >删除</el-button>
            </el-button-group>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        background
        class="paginationbox"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-sizes="[5, 10, 15, 20]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="totalCount"
      ></el-pagination>
    </div>
  </div>
</template>

<script>
import {
  getStoreWithdrawalsPage,
  updateStoreWithdrawalsList,
  deleteStoreWithdrawals
} from "@/utils/api";
export default {
  data() {
    return {
      tableData: [],
      currentPage: this.$route.params.currentPage || 1,
      totalCount: 0,
      pageSize: 20,
      dateRange: null,
      store_id: null,
      realname: null,
      bank_card: null,
      status: 0,
      statusArr: [
        {
          value: -2,
          label: "无效作废"
        },
        {
          value: -1,
          label: "申请失败"
        },
        {
          value: 0,
          label: "申请中"
        },
        {
          value: 1,
          label: "申请成功"
        }
      ]
    };
  },
  created() {
    this.getPage();
  },
  methods: {
    handleSizeChange(e) {
      this.pageSize = e;
      this.getPage();
    },
    handleCurrentChange(e) {
      this.currentPage = e;
      this.getPage();
    },
    getPage() {
      var that = this;
      var params = {
        page: this.currentPage,
        size: this.pageSize,
        status: this.status,
        store_id: this.store_id,
        realname: this.realname,
        bank_card: this.bank_card
      };
      if (this.dateRange) {
        params.start_time = this.dateRange[0] / 1000;
        params.end_time = this.dateRange[1] / 1000 + 86400;
      }
      getStoreWithdrawalsPage(params).then(function(res) {
        that.tableData = res.records;
        that.totalCount = res.total;
      });
    },
    refresh() {
      this.getPage();
      this.$message.success("刷新成功！");
    },
    updateBatch(status) {
      //获取选中的记录
      var rows = this.$refs.multipleTable.selection;
      var ids = [];
      rows.forEach(element => {
        ids.push(element.id);
      });
      if (ids.length == 0) {
        this.$message.info({
          message: "请选择需要修改的记录!"
        });
        return;
      }
      this.update(ids, status);
    },
    update(ids, status) {
      var that = this;
      updateStoreWithdrawalsList(ids, status).then(function(res) {
        if (res.status == 1) {
          that.$message.success("操作成功!");
          that.getPage();
        } else {
          that.$message.error({
            message: res.msg
          });
        }
      });
    },
    detail(id) {
      this.$router.push({
        name: "store_withdrawals_details",
        params: {
          id: id
        }
      });
    },
    delFn(id) {
      var that = this;
      this.$confirm("是否删除该信息?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          deleteStoreWithdrawals(id).then(function(res) {
            if (res.status == 1) {
              that.$message({
                type: "success",
                message: "删除成功!",
                onClose: function() {
                  that.getPage();
                }
              });
            }
          });
        })
        .catch(() => {
          that.$message.info("已取消删除");
        });
    }
  }
};
</script>

<style scoped>
.searchinput {
  width: auto;
}

>>> .el-range-editor--small .el-range-input {
  width: 100px;
}

>>> .el-range-editor--small.el-input__inner {
  width: 300px;
}

>>> .el-input--small .el-input__inner {
  width: 120px;
}
</style>
